<?php $this->html->loadJS("Content/gmode_newproduct/js/jquery.gzoom.js")?>
<script type="text/javascript">
$(document).ready(function(){
	$("#submitComment").submit(function(){
		data = {
    			memberID: $("#memberID").val(),
    			productID: $("#productID").val(),
    			content: $("#contentComment").val()
            };
    		$.ajax({
        		data: data,
        		type: "POST",
        		dataType: "json",
        		success: function(response){
    				if(response.success)
    				{
    					Boxy.alert("Gửi nhận xét thành công!");
    					$("#contentComment").val("");
    				}
    				else
    				{
    					Boxy.alert(response.error);
    				}
            	}
        	});
        return false;
	});
	
	 $("#current-image").gzoom({
       sW: 390,
       sH: 430,
       lW: 1236,
       lH: 1332,
       whiteSpace: 0,
       sliderWhiteSpace: 125,
       zoomInWhiteSpace: -13,
       buttonZoomInSrc: '<?php echo $this->url->content("Content/gmode_newproduct/images/ic_zoomout.jpg")?>',
       buttonZoomInWidth: 21,
       buttonZoomInHeight: 22,
       buttonZoomOutSrc: '<?php echo $this->url->content("Content/gmode_newproduct/images/ic_zoomin.jpg")?>',
       buttonZoomOutWidth: 21,
       buttonZoomOutHeight: 22,
       re : new RegExp('/' + 309 + 'x' + 333 + '/'),
       replace : 1236+'x'+1332,
       lighbox : false,
       drag : true,
       loaderContent: "",
       canReset: true,
       resetBgImage: '<?php echo $this->url->content("Content/gmode_newproduct/images/bg_reset.gif")?>',
       zoomBgImage: '<?php echo $this->url->content("Content/gmode_newproduct/images/bg_zoom.gif")?>',
       smoothMove: true,
       zoom0: true,
       zoom100: true
   });
	$(".swap-image").each(function(){
     bind_image_action(this);
   }); 

	$(".relativeImage").click(function(){
		$("#current-image").children('img').load(function () {                
        }).error(function (){
            show_popup("Error","Image does not exist or its SRC is not correct.");
        }).attr('src', $(this).attr("src"));
	});
});

function bind_image_action(element) {
		$(element).click(function(){
      	 	$(this).parent('li').siblings('li').removeClass('selected');
	        $(this).parent('li').addClass('selected');
			var tsrc = $(this).children('img').attr('src');
			var src = $(this).attr('rel');
			var found = false;
			main_image_el = $("#current-image").children('img');
			jQuery.each(main_image_el, function(i, value){
				if ($(value).attr('src') == src)
					found = true;
				$(value).hide();
			});
			if (found == false) {
				$("#current-image").append('<img width="276" height="361" src="'+tsrc+'" />');
				$("#current-image").children('img:last').load(function () {
					//loading
				}).error(function (){
					show_popup("Error","Image does not exist or its SRC is not correct.");
				}).attr('src', src);
				$("#current-image").children('img:last').hide();
			}
			$("#current-image").children('img:first').load(function () {
					//loading
				}).error(function (){
					show_popup("Error","Image does not exist or its SRC is not correct.");
				}).attr('src', src);
			$("#current-image").children('img:first').show();
		});
}
</script>
<style type="text/css">
.productinfoval
{
	font-weight: bold;
	font-size: 10pt;
	padding: 0;
	margin: 0;
}
</style>
<!-- Start main content -->
            <div class="main-content">
				<div style="float: left; background: url(<?php echo $this->url->content("Content/gmode_newproduct/images/goods_bg6.gif")?>) repeat-x left bottom;">
					<!-- Header -->
					<div class="content_header">
						<h2 class="centerBoxHeading">
						<?php echo $this->product['name']?>
						</h2>
					</div>
					<div class="content_detail">
						<div id="imageProduct-zoom">
							<div class="ct-left-prod">
				                <div class="bx-zoom-img">
				                    <div class="bx-img" id="current-image">
				                        <img src="<?php echo $this->product['image']?>"  alt="Kids parabou long slim top" />
				                    </div>
				                </div>
				                <!--div class="view-play">
				                    <a href="#">
				                        <img src="http://best.booztx.com/nameit/images/ic_viewvideo.gif" alt=""/>
				                        <p>Play video</p>
				                    </a>
				                </div-->
				            <script type="text/javascript">
				            //<![CDATA[
				            $(document).ready(function() {
				                $("#current-image").children('img').load(function () {                
				                        }).error(function (){
				                            show_popup("Error","Image does not exist or its SRC is not correct.");
				                        }).attr('src', '<?php echo $this->product['image'];?>');
				            });
				            //]]>
				            </script>
				                <div class="view-guide">
				                    <!-- a href="#"><img src="http://best.booztx.com/nameit/images/only_view_guide.gif" alt="" width="101" height="56" /></a -->
				                </div>
				                <div class="clear"><img src="<?php echo $this->url->content("Content/gmode_newproduct/images/00000000.gif")?>" alt="" width="1" height="37" /></div>
				            </div>
						</div>
						<div id="ProductInformation">
							<p class="title-product label"><h2>Thông tin sản phẩm: </h2></p>
							<p class="productinfoval"><?php $this->html->raw($this->product['description'])?></p>
							<p class="title-product label"><h2>Hãng/Nhãn hiệu: </h2></p>
							<p class="productinfoval"><?php echo $this->brands->getName($this->product['brandID'])?></p>
							<p class="title-product label"><h2>Chất liệu: </h2></p>
							<p class="productinfoval"><?php echo $this->materials->getName($this->product['materialID'])?></p>
							<p class="title-product label"><h2>Kích cỡ: </h2></p>
							<p class="productinfoval">
							<?php
								$arr = explode(',', $this->product['size']);
								foreach ($arr as $item)
								{
									echo $this->sizes->getName($item)."  ";
								}
							?>
							</p>
							<p class="title-product label"><h2>Giá: </h2></p>
							<p class="productinfoval"><?php echo number_format($this->product['price'],0,',','.').' '.$this->product['unit']?></p>
							<p>
								<a onclick="addCart(this)" data="<?php echo $this->product['id'];?>" ajaxify="<?php echo $this->url->action("addCart", "ShoppingCart")?>" title="<?php echo $this->product['name'];?>" dialog="<?php echo $this->url->action("addCartDialog", array($this->product['id']))?>">
									<div class="detail-button">Đặt hàng</div>
								</a>
							</p>
							<p><fb:like href="<?php echo $this->url->action("detail", "Products", array($this->product['id']))?>" show_faces="true" width="320"></fb:like></p>
						</div>
						<div id="ProductSubImage">
							<?php 
							//Hiển thị danh sách ảnh
							$arrImages = explode(",", $this->product['subimages']);
							foreach ($arrImages as $item)
							{
							?>
							<img class="relativeImage" src="<?php echo $item?>"/>
							<?php }?>
						</div>
						<div id="comment">
							<p class="comment-header-title"><h2>Nhận xét:</h2></p>
							<?php foreach ($this->arrComments as $comment)
							{?>
								<p class="comment-title"><?php $data = $this->users->getDetail($comment['memberID']); echo $data['fullname'];?>, <span style="font-size: 7pt; font-weight: normal;"><?php echo XPHP_Date::isTheDay($comment['date_create'])?></span></p>
								<p class="comment-content"><?php echo $comment['content']?>
								 </p>
							<?php }?>
							<div id="comment-form" <?php 
								//if (!isset($_SESSION['is_login']))
								//	echo 'style="display: none;"';
							?>>
							<p class="comment-header-title"><h2>Nhận xét của bạn:</h2></p>
								<div id="form-comment">
								<?php echo $this->html->beginForm("submitComment")?>
									<?php echo $this->html->hiddenFor('memberID',array("value" => "2"))?>
									<?php echo $this->html->hiddenFor('productID',array("value" => $this->product['id']))?>
									<table>
										<tr>
											<td><textarea name="contentComment" id="contentComment"></textarea></td>
										</tr>
										<tr>
											<td style="text-align: left"><input class="button-gray" type="submit" value="Đồng ý"/></td>
										</tr>
									</table>
								</div>
							</div>
						</div>
						
					</div>
				</div>
				<div style="float: left; width: 100%;">
					<div class="content_header">
						<h2 class="centerBoxHeading">
						Sản phẩm tương tự
						</h2>
					</div>
					<div class="content_detail">
					<?php foreach ($this->relativeProducts as $relativeProduct) {
					
					?>
						<div class="product-wrapper">
							<div class="product-image">
								<img src="images/01.jpg"/>
							</div>
							<div class="product-information">
								Mã sản phẩm: <?php echo $relativeProduct['id'];?><br/>
								
								Màu sắc: <?php echo $relativeProduct['color'];?><br>
								Mọi kích cỡ
							</div>
							<div class="product-bottom">
								<div class="facebook-button">
									<fb:like href="http://vnexpress.net" layout="button_count" show_faces="false" width="100"></fb:like>
								</div>
								<div class="detail-button">
									Đặt hàng
								</div>
								<div class="price">
									<?php echo number_format($relativeProduct['price'],0,',',' ').' '.$relativeProduct['unit'];?>
								</div>
							</div>
						</div>
					<?php }?>
					</div>
				</div>
            </div>
            <!-- End main content -->
            
<script type="text/javascript">
 	function addCart(obj)
 	{
 	 	$.get($(obj).attr("dialog"), function(data){
 	 		Boxy.ask(data, ['Đặt mua', 'Hủy bỏ'], function(val) {
 	 	 		if(val == 'Đặt mua')
 	 	 		{
 	 	 			jsondata = {
 	 	 	 	 			id : $(obj).attr("data"), 
 	 	 	 	 			color: $("#color").val(),
 	 	 	 	 			size: $("#size").val()
 	 	 	 	 	};
 	 	 			$.post($(obj).attr("ajaxify"), jsondata, function(res){
 	 					if(res.success)
 	 					{
 	 						Boxy.alert("<b>Đặt hàng thành công !</b>");
 	 						$("#_cartItemCount").html(res.cart_total);
 	 					}
 	 				}
 	 				, "json")
 	 	 	 	}   
  	  	     }, {title: 'Đặt mua ' + $(obj).attr("title")});
 	 	});
 	}
 </script>